package com.woniuxy.stage3demo.controller.kang;

import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.ResultMsg;
import com.woniuxy.stage3demo.bean.kang.CousBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.kang.ICousService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/cous")
public class CousController {

    @Resource
    private ICousService cousServiceImpl;

    @GetMapping(value = "/findLimit",produces = {"application/json;charset=utf-8"})
    public ResultMsg findLimit(PageRequest pageRequest, CousBean cousBean){
//        System.out.println(pageRequest+"````"+cousBean);

        PageInfo<CousBean> cous = cousServiceImpl.findLimit(pageRequest, cousBean);

        return new ResultMsg(200,"成功",new TableResult<>(cous.getTotal(),cous.getList()));
    }

    @DeleteMapping(value = "/{id}",produces = {"application/json;charset=utf-8"})
    public ResultMsg findLimit(@PathVariable("id") Long id){
        System.out.println(id);

        cousServiceImpl.deleteCous(id);

        return new ResultMsg(200,"成功",null);
    }

    @PostMapping(value = "/addCous",produces = {"application/json;charset=utf-8"})
    public ResultMsg addCous(@RequestBody CousBean cousBean){
        System.out.println(cousBean);

        cousServiceImpl.addCous(cousBean);

        return new ResultMsg(200,"成功",null);
    }

    @PutMapping(value = "/modCous",produces = {"application/json;charset=utf-8"})
    public ResultMsg modCous(@RequestBody CousBean cousBean){
        System.out.println(cousBean);

        cousServiceImpl.updateCous(cousBean);

        return new ResultMsg(200,"成功",null);
    }

}
